<template>
  <page-header-wrapper>
    <page-tab-list>
      <div class="table-page-search-box">
        <a-form layout="inline">
          <a-row :gutter="24">
			<a-col :md="8" :sm="24">
			  <a-form-item label="用户id">
			    <a-input-search allowClear v-model="queryParam.userid" placeholder="请输入用户id" />
			  </a-form-item>
			</a-col>   
            <a-col :md="8" :sm="24">
              <a-form-item label="会员昵称">
                <a-input placeholder="请输入会员昵称" v-model="queryParam.name"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="申请时间">
                <a-range-picker
                  format="YYYY-MM-DD HH:mm"
                  valueFormat="YYYY-MM-DD HH:mm"
                  :placeholder="['开始时间', '结束时间']"
                  v-model="queryTime"
                  @change="changeTime"
                />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="操作时间">
                <div class="select">
                  <a-range-picker
                    format="YYYY-MM-DD HH:mm"
                    valueFormat="YYYY-MM-DD HH:mm"
                    :placeholder="['开始时间', '结束时间']"
                    v-model="queryTime1"
                    @change="changeTime1"
                  />
                  <a-button type="primary" @click="getList">查询</a-button>
                </div>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </page-tab-list>
    <a-card :bordered="false">
      <div class="table-operator" style="display: flex; justify-content: space-between">
        <a-radio-group v-model="queryParam.status" @change="getList">
          <a-radio-button value="-1"> 全部 </a-radio-button>
          <a-radio-button value="0"> 未审核 </a-radio-button>
          <a-radio-button value="1"> 已审核 </a-radio-button>
          <a-radio-button value="3"> 已拒绝 </a-radio-button>
          <a-radio-button value="2"> 已打款 </a-radio-button>
        </a-radio-group>
      </div>
      <a-table
        :rowKey="
          (r, i) => {
            return r.id
          }
        "
        :pagination="{
          total: this.totalCount,
          showSizeChanger: false,
          onChange: this.tablePageChange,
        }"
        :columns="columns"
        :data-source="list"
        :scroll="{ x: 'man-content' }"
      >
        <div slot="name" slot-scope="text, record">
          <div class="name">
            <div class="pic">
              <img :src="record.new_avatar || record.avatar_url" alt="" />
            </div>
            <div class="info">
              <span>{{ record.new_name || record.nickname }}</span>
            </div>
          </div>
        </div>
        <span slot="mobile" slot-scope="scope"> {{ scope.name }} / {{ scope.mobile }} </span>
        <span slot="created_at" slot-scope="text">
          {{ text > 0 ? $moment(text * 1000).format('YYYY-MM-DD HH:mm:ss') : '-' }}
        </span>
        <span slot="updated_at" slot-scope="text">
          {{ text > 0 ? $moment(text * 1000).format('YYYY-MM-DD HH:mm:ss') : '-' }}
        </span>
        <div slot="status" slot-scope="scope">
          <div class="status">
            <span
              :class="scope == 0 ? 'waiting' : scope == 1 ? 'close' : scope == 2 ? 'open' : scope == 3 ? 'refuse' : ''"
            ></span>
            <span>{{
              scope == 0 ? '未处理' : scope == 1 ? '待打款' : scope == 2 ? '已完成' : scope == 3 ? '已拒绝' : ''
            }}</span>
          </div>
        </div>
        <span slot="accountinfo" slot-scope="text, scoped">
          <template v-if="scoped.type == 0">
            <div class="style-font">姓名：{{ scoped.name }}</div>
            <span class="style-font">微信号：{{ scoped.mobile }}</span>
            <div class="style-font">提现到微信</div>
          </template>
          <template v-if="scoped.type == 1">
            <div class="style-font">姓名：{{ scoped.name }}</div>
            <span class="style-font">支付宝：{{ scoped.mobile }}</span>
            <div class="style-font">提现到支付宝</div>
          </template>
          <template v-if="scoped.type == 2">
            <div class="style-font">姓名：{{ scoped.name }}</div>
            <div class="style-font">开户行：{{ scoped.bank_name }}</div>
            <span class="style-font">银行卡号：{{ scoped.mobile }}</span>
            <div class="style-font">提现到银行</div>
          </template>
          <template v-if="scoped.type == 3">
            <div class="style-font">余额提现</div>
          </template>
        </span>
        <span slot="cashinfo" slot-scope="text, scoped">
          <div class="style-font">提现金额：{{ scoped.price }}</div>
          <div class="style-font">手续费：{{(scoped.price - scoped.money).toFixed(2) }}</div>
          <!-- <div class="style-font">实际打款金额：{{ record.money }}</div> -->
        </span>
        <span slot="money" slot-scope="money">
          ￥{{money || 0}}
        </span>
        <div class="action" slot="action" slot-scope="scoped">
          <a-button
            type="link"
            v-if="scoped.status != 1"
            :disabled="scoped.status == 3 || scoped.status == 2 ? true : false"
            @click="changeStatus(scoped.id, 1)"
            >通过</a-button
          >
          <a-button
            type="link"
            v-if="scoped.status == 1"
            :disabled="scoped.status == 3 || scoped.status == 2 ? true : false"
            @click="changeStatus(scoped.id, 3)"
            >拒绝</a-button
          >
          <span class="line"></span>
          <a-button
            type="link"
            v-if="scoped.status != 1"
            :disabled="scoped.status == 3 || scoped.status == 2 ? true : false"
            @click="changeStatus(scoped.id, 3)"
            >拒绝</a-button
          >
          <a-dropdown v-if="scoped.status == 1" :disabled="scoped.status == 3 || scoped.status == 2 ? true : false">
            <a-button type="link" :disabled="scoped.status == 3 || scoped.status == 2 ? true : false"
              >更多<a-icon type="down"
            /></a-button>
            <a-menu slot="overlay">
              <a-menu-item v-if="[0,1].includes(parseInt(scoped.type))" @click="confirmWithdraw(scoped.id, 2)"> 确认打款 </a-menu-item>
              <a-menu-item @click="confirmWithdraw(scoped.id, 4)"> 手动打款 </a-menu-item>
            </a-menu>
          </a-dropdown>
        </div>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { cashList, cashApply, cashConfirm } from '@/api/shareholder'
const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
  },
  {
    title: '会员信息',
    scopedSlots: {
      customRender: 'name',
    },
    width: 200,
  },
  {
    title: '会员等级',
    dataIndex: 'level_name',
  },
  {
    title: '账号信息',
    dataIndex: 'type',
    width: 220,
    scopedSlots: { customRender: 'accountinfo' },
  },
  {
    title: '提现信息',
    scopedSlots: { customRender: 'cashinfo' },
  },
  {
    title: '实际打款',
    dataIndex: 'money',
    scopedSlots: {
      customRender: 'money',
    }
  },
  {
    title: '状态',
    dataIndex: 'status',
    scopedSlots: {
      customRender: 'status',
    },
  },
  {
    title: '申请时间',
    dataIndex: 'created_at',
    scopedSlots: {
      customRender: 'created_at',
    },
    sorter: (a, b) => a.created_at - b.created_at,
  },
  {
    title: '操作时间',
    dataIndex: 'updated_at',
    scopedSlots: {
      customRender: 'updated_at',
    },
    sorter: (a, b) => a.updated_at - b.updated_at,
  },
  {
    title: '操作',
    width: 180,
    scopedSlots: {
      customRender: 'action',
    },
  },
]
export default {
  data() {
    return {
      // 搜索参数
      queryParam: {
		userid: null,  
        name: null,
        start_time: null,
        end_time: null,
        audit_start_time: null,
        audit_end_time: null,
        status: '0',
        pageNo: 1,
        pageSize: 10,
      },
      // 请求的数据列表
      list: [],
      // 表格列配置
      columns,
      // 数据条数
      totalCount: 0,
      // 下单时间
      queryTime: [],
      // 生成时间
      queryTime1: [],
    }
  },
  methods: {
    // 获取数据列表
    async getList() {
      const hide = this.$message.loading('加载中', 0)
      const res = await cashList(this.queryParam)
      if (res.code == 0) {
        this.totalCount = res.data.totalCount
        this.list = res.data.data
      }
      hide()
    },
    // 分页请求
    tablePageChange(e) {
      this.queryParam.pageNo = e
      this.getList()
    },
    // 切换筛选时间
    changeTime(e) {
      if (e.length) {
        this.queryParam.start_time = e[0]
        this.queryParam.end_time = e[1]
      } else {
        this.queryParam.start_time = null
        this.queryParam.end_time = null
      }
    },
    // 切换筛选时间
    changeTime1(e) {
      if (e.length) {
        this.queryParam.audit_start_time = e[0]
        this.queryParam.audit_end_time = e[1]
      } else {
        this.queryParam.audit_start_time = null
        this.queryParam.audit_end_time = null
      }
    },
    // 单个修改状态
    changeStatus(id, status) {
      let that = this
      let text = status == 3 ? '拒绝' : '同意'
      this.$confirm({
        title: '是否' + text + '申请?',
        async onOk() {
          that.status([id], status)
        },
        onCancel() {},
      })
    },
    // 点击确认打款
    confirmWithdraw(id, status) {
      let that = this
      let text = status == 2 ? '确认打款' : '确认手动打款'
      this.$confirm({
        title: '是否' + text + '?',
        async onOk() {
          const res = await cashConfirm({ id, status })
          if (res.code == 0) {
            that.getList()
          }
        },
        onCancel() {},
      })
    },
    // 修改状态
    async status(id, status) {
      const res = await cashApply({ id, status })
      if (res.code == 0) {
        this.getList()
      }
    },
  },
  mounted() {
    this.getList()
  },
}
</script>

<style lang="less" scoped>
.search {
  /deep/ .ant-card-body {
    padding-top: 0 !important;
    padding-bottom: 14px !important;
  }
}
.searchBox {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  /deep/ .ant-input-affix-wrapper {
    width: 220px;
    margin-top: 14px;
    margin-right: 20px;
  }
  .select {
    display: flex;
    align-items: center;
    margin-top: 14px;
    margin-right: 20px;
  }
  .ant-btn {
    margin-top: 14px;
  }
}
.name {
  display: flex;
  align-items: center;
  .pic {
    width: 48px;
    min-width: 48px;
    height: 48px;
    border-radius: 4px;
    overflow: hidden;
    margin-right: 24px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .info {
    flex: auto;
    width: 0;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    span {
      width: 100%;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    span:nth-child(2) {
      color: rgba(0, 0, 0, 0.45);
      margin-top: 6px;
    }
  }
}
.status {
  display: flex;
  align-items: center;
  span:nth-child(1) {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 8px;
  }
  .close {
    background-color: #c6c6c6;
  }
  .open {
    background-color: #65c817;
  }
  .refuse {
    background-color: #f5222d;
  }
  .waiting {
    background-color: #faad14;
  }
}
.action {
  display: flex;
  align-items: center;
  .line {
    width: 1px;
    height: 14px;
    background-color: #d8d8d8;
  }
}
</style>